import axios from 'axios' // cnpm install axios --save 没有安装的先安装好插件 cnpm是淘宝镜像自行配置

const service = axios.create({
  timeout: 10000, // 10s超时
  headers: {
    'Content-Type': 'application/json'
  }
})

service.interceptors.request.use(
  config => {
    // 拦截器
    // console.log(config)
    return config
  },
  error => {
    console.log(error)
    return Promise.reject()
  }
)

service.interceptors.response.use(
  response => {
    if (response.status === 200) {
      return response
    } else {
      Promise.reject()
    }
  },
  error => {
    console.log(error)
    return Promise.reject()
  }
)

export default service
